#include<iostream>
using namespace std;
const int N = 1e3 + 10;
int father[N];
int Find(int x)
{
	int t = x;
	while (t != father[t])
	{
		t = father[t];
	}
	return t;
}

void Union(int x, int y)
{
	int Ax = Find(x);
	int Ay = Find(y);
	if (Ax != Ay)
	{
		father[Ax] = Ay;
	}
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, m;
		cin >> n >> m;
		for (int i = 1; i < n + 1; i++)
		{
			father[i] = i;
		}
		while (m--)
		{
			int x, y;
			cin >> x >> y;
			Union(x, y);
		}
		int count = 0;
		for (int i = 1; i < n+1; i++)
		{
			if (father[i] == i)
			{
				count++;
			}
		}
		cout << count << endl;
	}
	return 0;
}